package com.ZeroCarbon.service.impl;

import com.ZeroCarbon.domain.po.UserComment;
import com.ZeroCarbon.exception.BusinessLogicException;
import com.ZeroCarbon.mapper.UserCommentMapper;
import com.ZeroCarbon.service.IUserCommentService;
import com.ZeroCarbon.utils.UserHolder;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import static com.ZeroCarbon.exception.BusinessLogicException.ERROR_EXCEPTION;

@Service
public class UserCommentServiceImpl extends ServiceImpl<UserCommentMapper, UserComment> implements IUserCommentService {

    /**
     * 添加用户与评论关系
     *
     * @param id 评论id
     */
    @Override
    public Boolean postComment(String id) throws BusinessLogicException {
        //获取用户id
        String userId = UserHolder.getUser();
        try {
            //用户评论类
            UserComment userComment = new UserComment(id, userId);
            //保存用户评论类
            return save(userComment);
        } catch (Exception e) {
            throw new BusinessLogicException(ERROR_EXCEPTION);
        }
    }
}
